package com.jarvis.zeng.design.pattern.filter.datapermission;

import com.sun.istack.internal.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class SpringUtils implements ApplicationContextAware {
    private static ApplicationContext applicationContext;
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringUtils.applicationContext = applicationContext;
    }

    public static <T> List<T> getBeansOfType(Class<T> clazz)
    {
        Map<String,T> map = applicationContext.getBeansOfType(clazz);
        return new ArrayList<T>(map.values());
    }
}
